package handlers

import (
	"cron-go/configs/error_code"
	"cron-go/internal/pkg/crontab/dao"

	"github.com/go-liam/util/conv"
	"github.com/go-liam/util/response"
)

type DeleteTask struct {
	Req     *DeleteTaskReq
	Message string
	IDs     []int64
}

type DeleteTaskReq struct {
	IDs []string `json:"ids" validate:"required" ` // crontab
}

func (s *DeleteTask) GetData() *response.APIResponse {
	s.Change()
	num, err := new(dao.TaskDao).Delete(s.IDs)
	data := make(map[string]interface{})
	data["num"] = num
	data["error"] = err
	return &response.APIResponse{Code: error_code.Success, Message: error_code.MsSuccess, Data: data}
}

func (s *DeleteTask) Change() {
	s.IDs = conv.ArrayStringToInt64(s.Req.IDs)
}
